package com.app.mvc.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.jasper.tagplugins.jstl.core.Redirect;

import com.app.mvc.dao.CategoryDao;
import com.app.mvc.dao.DealDao;
import com.app.mvc.dao.DealImageDao;
import com.app.mvc.dao.LocationDao;
import com.app.mvc.dao.impl.CategoryDaoImpl;
import com.app.mvc.dao.impl.DealDaoImpl;
import com.app.mvc.dao.impl.DealImageDaoImpl;
import com.app.mvc.dao.impl.LocationDaoImpl;
import com.app.mvc.model.Category;
import com.app.mvc.model.Deal;
import com.app.mvc.model.DealImage;
import com.app.mvc.model.Location;

public class DealDetailController extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		DealDao deDao = new DealDaoImpl();
		DealImageDao dealImageDao = new DealImageDaoImpl();

		String id = req.getParameter("code");
		
		Deal deal = deDao.findById(Long.parseLong(id));
		System.out.println(deal.getTitle());
		req.setAttribute("deal", deal);

		List<DealImage> images = dealImageDao
				.getImageByDeal(Long.parseLong(id));
		req.setAttribute("images", images);

		RequestDispatcher view = req.getRequestDispatcher("jsp/detail.jsp");
		view.forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}

}
